package com.culture.config.wrapper;

import java.util.Optional;

import com.culture.config.common.util.BeanUtil;
import com.culture.config.dao.entity.Role;
import com.culture.config.model.po.*;
import com.culture.config.util.AuthenticationUtil;

import org.apache.commons.lang3.StringUtils;

import lombok.experimental.UtilityClass;

@UtilityClass
public class RoleWrapper {
    public static Role wrapRoleQuery(RolePageParam param) {
		Role role = new Role();	  
		if(StringUtils.isNotBlank(param.getRoleName())){
			role.setRoleName(param.getRoleName());
		}		
		return role;
	}		

	public static Role wrapRoleAdd(RoleAddPO roleAddPO) {
		Role role = BeanUtil.copyProperties(roleAddPO, Role.class);
		role.setDeleted(0);
		AuthenticationUtil.setInsertFieldInfo(role);
		return role;
	}
	
	public static Role wrapRoleUpdate(RoleUpdatePO roleUpdatePO) {
		Role role = BeanUtil.copyProperties(roleUpdatePO, Role.class);
		Optional.ofNullable(roleUpdatePO.getStatus()).ifPresent(status->{
			role.setDeleted(status);
		});
		AuthenticationUtil.setUpdateFieldInfo(role);	
		return role;
	}

	public static Role wrapRoleSearch(RoleSearchPO param) {
		Role role = new Role();	  
		if(StringUtils.isNotBlank(param.getRoleName())){
			role.setRoleName(param.getRoleName());
		}		
		return role;
	}		
}
